home *** CD-ROM | disk | FTP | other *** search
- Path: news1.erols.com!newsmaster@erols.com
- From: Chris Cobb <ccobb@erols.com>
- Newsgroups: comp.lang.c++
- Subject: SEX & C++
- Date: 17 Mar 1996 14:27:37 GMT
- Organization: CSEG, Inc.
- Message-ID: <4ih7gp$tdt@news5.erols.com>
- References: <4idbcv$ue2@news7.erols.com>
- NNTP-Posting-Host: ccobb.erols.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22KIT (Windows; U; 16bit)
-
- OK, so the subject line is only half true. But now that I have your
- attention, can someone please tell me if the following code works on
- their compiler and/or if the code is conformant ANSI C++. I have tried
- it on three recent-version C++ compilers and it only works on one of
- them. Since this is such a simple example and will only take you a
- couple of minuites to enter into your compiler, I challenge you all to
- find out if this works on your compiler.
-
- The implications are tremendous. If I have a constant, MYCONST, that is
- defined in a header xxx.h, and let's say twenty-five other source files
- use it: if I change MYCONST, then I have to recompile twenty-five source
- files.
-
- In the following scenario, I only have to recompile ONE source file, and
- all of the rest can be used without recompiling. Try it out!
-
- --- xxx.h ---
- extern const int MYCONST; // can you declare a const extern?
- --- end xxx.h ---
-
- --- xxx.cc ---
- #include "xxx.h"
- const int MYCONST = 11; // const defined in one file...
- --- end xxx.cc ---
-
- --- yyy.cc ---
- #include <iostream.h>
- #include "xxx.h"
- main()
- {
- char myarray[MYCONST]; // and used in another!
-
- cout << "MYCONST is " << MYCONST << endl;
- cout << "sizeof myarray[] is " << sizeof(myarray) << endl;
- return 0;
- }
- --- end yyy.c ---
-
- Chris
- ccobb@cseg.com
-
-